import collegeRoutes from "./collegeRoutes";
import eduAdminRoutes from "./eduAdminRoutes";
import systemRoutes from './systemRoutes';

//根据用户部门 获取 路由信息 
function getRoutes(roles) {
    if(roles=='superuser'){
        window.localStorage.setItem('userroutes',JSON.stringify(systemRoutes))
        return systemRoutes
    }
    //获取用户的角色信息
    if(!roles || roles.length==0) return false
    //获取用户所属的部门
    let department='college'
    roles.forEach(item => {
        if(!item.department.is_school){
            department='edu_admin'
        }
    });
    //获取部门下的路由集合  假设部门是学院
    var routes=collegeRoutes
    if(department=='edu_admin'){
        routes=eduAdminRoutes
    }
    //根据岗位级别进行筛选
    routes.children=routes.children.filter(item=>{
        const level=item.meta.level
        if(level){
            if(Array.isArray(level)){
                return item.meta.level.includes(roles[0].level)
            }
            //根据岗位级别进行筛选
            return item.meta.level==roles[0].level
        }
        return true
    })
    //根据岗位职责进行筛选
    routes.children=routes.children.filter(item=>{
        const duty=item.meta.duty
        if(duty){
            if(Array.isArray(duty)){
                return item.meta.level.includes(roles[0].duty)
            }
            //根据岗位级别进行筛选
            return item.meta.duty==roles[0].duty
        }
        return true
    })
    window.localStorage.setItem('userroutes',JSON.stringify(routes))
    return routes
}
export default getRoutes